/**
 * @file testBenchmark.cpp
 * @brief test Benchmark
 * @author JakeYang <add358@gmail.com>
 * @version 0.1
 * @date 2016-03-31
 */

#include <QtTest/QtTest>

class TestBenchmark : public QObject {
	Q_OBJECT
private slots:
	void simple();
	void multiple_data();
	void multiple();
};


void TestBenchmark::simple()
{
	QString s1 = QLatin1String("This is a test string");
	QString s2 = QLatin1String("This is a test string");

	QCOMPARE(s1.localeAwareCompare(s2), 0);

	QBENCHMARK {
		s1.localeAwareCompare(s2);
	}
}

void TestBenchmark::multiple_data()
{
	QTest::addColumn<bool>("useLocaleCompare");
	QTest::newRow("locale aware compare") << true;
	QTest::newRow("standard compare") << false;
}

void TestBenchmark::multiple()
{
	QFETCH(bool, useLocaleCompare);
	QString s1 = QLatin1String("This is a test string");
	QString s2 = QLatin1String("This is a test string");

	int result;
	if (useLocaleCompare) {
		QBENCHMARK {
			result = s1.localeAwareCompare(s2);
		}
	} else {
		QBENCHMARK {
			result = (s1 == s2);
		}
	}

	Q_UNUSED(result);
}

QTEST_MAIN(TestBenchmark)
#include "testBenchmark.moc"
